﻿// --------------------------------
// <copyright file="ReportsViewer.cs" company="Pattern Web Solutions">
//     Copyright © Simon Gill 2010. Distributed under the GPL.
// </copyright>
// <author>Simon Gill</author>
// ---------------------------------
// This file is part of League Manager

// League Manager is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.

// League Manager is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with League Manager.  If not, see <http://www.gnu.org/licenses/>.

namespace LeagueManager
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using LeagueManager.Models;
    using Microsoft.Reporting.WinForms;

    public partial class ReportsViewer : Form
    {
        private IMembershipRepository membership;

        public ReportsViewer(IMembershipRepository repository)
        {
            this.InitializeComponent();

            this.spinYear.Value = DateTime.Now.Year;
            this.spinMonth.Value = DateTime.Now.Month;

            this.membership = repository;
        }

        private void LeagueStandingsReport_Click(object sender, EventArgs e)
        {
            this.reportViewer.Reset();

            this.membership.UpdateStandingsForMonth(Convert.ToInt32(this.spinYear.Value), Convert.ToInt32(this.spinMonth.Value));

            var list = this.membership.AllPlayersRankedByLeaguePoints(Convert.ToInt32(this.spinYear.Value), Convert.ToInt32(this.spinMonth.Value));

            this.reportViewer.LocalReport.ReportEmbeddedResource = "LeagueManager.LeagueRanking.rdlc";

            ReportDataSource leagueSource = new ReportDataSource("LeagueRanking", list);

            this.reportViewer.LocalReport.DataSources.Clear();
            this.reportViewer.LocalReport.DataSources.Add(leagueSource);

            this.reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
            this.reportViewer.RefreshReport();
        }

        private void ProStandings_Click(object sender, EventArgs e)
        {
            this.reportViewer.Reset();

            this.membership.UpdateStandingsForYear(Convert.ToInt32(this.spinYear.Value));

            var list = this.membership.AllPlayersRankedByProPoints(Convert.ToInt32(this.spinYear.Value));

            this.reportViewer.LocalReport.ReportEmbeddedResource = "LeagueManager.LeagueProStanding.rdlc";

            ReportDataSource leagueSource = new ReportDataSource("LeagueProStanding", list);

            this.reportViewer.LocalReport.DataSources.Clear();
            this.reportViewer.LocalReport.DataSources.Add(leagueSource);

            this.reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
            this.reportViewer.RefreshReport();
        }

        private void ReportsViewer_Load(object sender, EventArgs e)
        {
            this.reportViewer.RefreshReport();
        }
    }
}
